/**
 * 2024/7/28  Cjj 10:40
 * lazy loading
 * 懒汉式
 * 虽然达到了按需初始化的目的,但却带来线程不安全的问题
 * 可以通过synchronized解决，但也带来效率下降
 */
public class test3 {
    private static test3 INSTANCE;
    private test3(){}
    public static test3 getInstance(){
        if(INSTANCE == null){
           synchronized (test3.class){
               try {
                   Thread.sleep(1);
               }catch (InterruptedException e){
                   e.printStackTrace();
               }
           }
            INSTANCE = new test3();
        }
        return INSTANCE;
    }

    public void m(){
        System.out.println("m");
    }

    public static void main(String[] args) {
        for (int i = 0; i <100 ; i++) {
             new Thread(()->{
                 System.out.println(test3.getInstance().hashCode());
             }).start();
        }
    }
}
